import { UserProfilesAPI } from "@/request/api";
export default {
    //用户信息库
    namespaced: true,
    state: {
        //默认的购物车总数
        cartTotal: 10,
        userInfo: {//初始信息
            nickName: "游客",
            coin: 0,
            //图片路径抽取了之后当成模块来使用
            headImg: require("../../assets/img/userImg.f8bbec5e.png")
        }
    },
    mutations: {
        chanUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {//初始化用户信息
            state.cartTotal = 10;
            state.userInfo = {//初始信息
                nickName: "游客",
                coin: 0,
                //图片路径抽取了之后当成模块来使用
                headImg: require("../../assets/img/userImg.f8bbec5e.png")
            }
        }
    },
    actions: {
        async asyncChanUserInfo({ commit }) {
            let userInfoRes = await UserProfilesAPI();
            commit("chanUserInfo", userInfoRes.data)
        }
    },
}